import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:online_study/base/AlertUtils.dart';
import 'package:online_study/base/app_title.dart';
import 'package:online_study/mine/exam/exam_history.dart';
import 'package:online_study/mine/exam/start_exam.dart';
import 'package:online_study/theme/colors.dart';
import 'package:online_study/theme/size.dart';

//考试列表
class ExamListPage extends StatefulWidget {
  @override
  _ExamListPageState createState() => _ExamListPageState();
}

class _ExamListPageState extends State<ExamListPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: BackButton(color: ThemeColor.color333333),
        titleSpacing: 0,
        elevation: ThemeSize.appElevation,
        backgroundColor: ThemeColor.colorWhite,
        title: AppTitle("员工考试"),
        actions: [
          GestureDetector(
            child: Container(
              alignment: Alignment.center,
              margin: EdgeInsets.only(right: ThemeSize.width19),
              child: Text("考试记录",
                  style: TextStyle(
                      color: ThemeColor.color333333, fontSize: ThemeSize.sp13)),
            ),
            onTap: () {
              Get.to(() => ExamHistoryPage());
            },
          )
        ],
      ),
      body: ListView.separated(
          itemBuilder: (BuildContext context, int index) {
            return Container(
              padding: EdgeInsets.symmetric(horizontal: ThemeSize.width19),
              width: double.infinity,
              height: ThemeSize.height84,
              color: ThemeColor.colorWhite,
              child: Row(
                children: [
                  Expanded(
                      child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text("员工日常行为规范一期补考",
                          style: TextStyle(
                              color: ThemeColor.color333333,
                              fontSize: ThemeSize.sp13,
                              fontWeight: FontWeight.bold)),
                      Container(
                        margin: EdgeInsets.only(top: ThemeSize.height18),
                        child: Text("考试时长：45分钟",
                            style: TextStyle(
                                color: ThemeColor.color555555,
                                fontSize: ThemeSize.sp10)),
                      ),
                      Container(
                        margin: EdgeInsets.only(top: ThemeSize.height6),
                        child: Text("考试时间范围：2021-04-02至2021-04-08",
                            style: TextStyle(
                                color: ThemeColor.color555555,
                                fontSize: ThemeSize.sp10)),
                      ),
                    ],
                  )),
                  (index == 0) ? _buildLeft(false) : _buildLeft(true)
                ],
              ),
            );
          },
          separatorBuilder: (BuildContext context, int index) {
            return Divider(height: ThemeSize.width1);
          },
          itemCount: 5),
    );
  }

  Widget _buildLeft(bool isTimeout) {
    if (isTimeout) {
      return Container(
        alignment: Alignment.topLeft,
        padding: EdgeInsets.only(top: ThemeSize.height12),
        child: Container(
          alignment: Alignment.center,
          height: ThemeSize.height22,
          width: ThemeSize.width50,
          decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(ThemeSize.height12),
              color: ThemeColor.colorF2F2F2),
          child: Text("已过期",
              style: TextStyle(
                  color: ThemeColor.colorWhite, fontSize: ThemeSize.sp10)),
        ),
      );
    } else {
      return Container(
        alignment: Alignment.topLeft,
        padding: EdgeInsets.only(top: ThemeSize.height12),
        child: GestureDetector(
          child: Container(
            alignment: Alignment.center,
            height: ThemeSize.height22,
            width: ThemeSize.width50,
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(ThemeSize.height12),
                color: ThemeColor.color1485EE),
            child: Text("去考试",
                style: TextStyle(
                    color: ThemeColor.colorWhite, fontSize: ThemeSize.sp10)),
          ),
          onTap: () {
            // Get.to(() => StartExamPage());
            buildDialog();
          },
        ),
      );
    }
  }

  void buildDialog() {
    showDialog(
        context: context,
        builder: (context) {
          return AlertUtils.haveCloseDialog(
              "信息中心-员工日常行为规范考试", ThemeColor.color1485EE, "考试时长：45分钟", "好的，立即考试",
              () {
            Get.back();
          }, () {
            Get.back();
            Get.to(() => StartExamPage());
          });
        });
  }
}
